package com.hcss.sys.versionitem.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hcss.paging.service.SchemaPagingByExample;
import com.hcss.sys.versionitem.dao.HcSysVersionitemMapper;
import com.hcss.sys.versionitem.model.HcSysVersionitem;
import com.hcss.sys.versionitem.model.HcSysVersionitemExample;
import com.hcss.sys.versionitem.model.par.HcSysVersionitemPar;
import com.hcss.sys.versionitem.service.HcSysVersionitemService;
import com.hcss.util.EmptyUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @描述: HcSysVersionitem-服务的实现类
 * @作者: fangtao
 * @创建日期: 2019-08-07 07:52:13
 */
@Service("hcSysVersionitemService")
public class HcSysVersionitemServiceImpl implements HcSysVersionitemService {
	
	@Autowired
	private HcSysVersionitemMapper hcSysVersionitemMapper;

	@Override
	public PageInfo<HcSysVersionitem> queryPagingData(HcSysVersionitemPar par) throws Exception{
        HcSysVersionitemExample example = (HcSysVersionitemExample) SchemaPagingByExample.getBaseExample(HcSysVersionitemExample.class, par);
        PageHelper.startPage(par.getPage(), par.getPerpage());
        List<HcSysVersionitem> list =  hcSysVersionitemMapper.selectByExample(example);
        return new PageInfo<>(list);
	}
	
	@Override
	public List<HcSysVersionitem> queryAllData(HcSysVersionitemPar par) throws Exception {
		HcSysVersionitemExample example = (HcSysVersionitemExample) SchemaPagingByExample.getBaseExample(HcSysVersionitemExample.class, par);
		return hcSysVersionitemMapper.selectByExample(example);
	}

	@Override
	public void insertModel(HcSysVersionitem model) {
		hcSysVersionitemMapper.insertSelective(model);
	}

	@Override
	public void updateModel(HcSysVersionitem model) {
        HcSysVersionitemExample example = new HcSysVersionitemExample();
        // 补充更新条件
        hcSysVersionitemMapper.updateByExampleSelective(model, example);
	}

	@Override
	public void deleteByIds(List<String> ids) {
		HcSysVersionitemExample example = new HcSysVersionitemExample();
		example.createCriteria().andIdIn(ids);
		hcSysVersionitemMapper.deleteByExample(example);
	}
	
	@Override
	public HcSysVersionitem selectByPK(String id) {
		if (EmptyUtil.isHaveEmpty(id)) return null;

        HcSysVersionitemExample example = new HcSysVersionitemExample();
        example.createCriteria().andIdEqualTo(id);
		List<HcSysVersionitem> list = hcSysVersionitemMapper.selectByExample(example);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
	}
}
